package ufabc.edu.helppo.gerador;

import java.util.List;
import java.security.MessageDigest;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Query;

import ufabc.edu.helppo.persistencia.HibernateUtil;
import ufabc.edu.helppo.persistencia.entidades.Usuario;
import ufabc.edu.helppo.persistencia.entidades.Regiao;

public class Regioes {

	public static List<Regiao> listaRegioes() {
		Session session = HibernateUtil.getSessionFactory().openSession();
		List<Regiao> lista = (List<Regiao>) session.createQuery("FROM Regiao")
				.list();
		session.close();
		return lista;
	}
	
	public static List<Regiao> listaRegioes(String UUID) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		List<Regiao> lista = (List<Regiao>) session.createQuery("FROM Regiao WHERE owner_uuid = '"+UUID+"'")
				.list();
		session.close();
		return lista;
	}

	public static Regiao pegaRegiao(String UUID) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		String hql = "from Regiao where uuid= '" + UUID + "'";
		Regiao region = (Regiao) session.createQuery(hql).uniqueResult();
		session.close();
		return region;
	}

	public static boolean possuiRegiao(String UUID) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		List<Regiao> lista = (List<Regiao>) session.createQuery("FROM Regiao where owner_uuid='"+UUID+"'")
				.list();
		session.close();
		return (!lista.isEmpty());
	}

}
